import 'package:flutter/material.dart';
import '../../widget/PPBaseWidget.dart';
import '../shop/homePage/PPShopHomePage.dart';
import '../menu/PPMenuPage.dart';
import '../message/homePage/PPMessageHomePage.dart';
import '../mine/PPMinePage.dart';
import '../../request/PPSaltManager.dart';

class PPTabBarPage extends StatefulWidget with PPBaseWidget {
    
    @override
    _PPTabBarPageState createState() => _PPTabBarPageState();
}

class _PPTabBarPageState extends State<PPTabBarPage> with SingleTickerProviderStateMixin {

    TabController _tabController;

    //生命周期方法插入渲染树时调用，只调用一次
    void initState() {
        super.initState();
        _tabController = TabController(vsync: this, length: 4);
        PPSaltManager().requestExchangeKey();
    }

    //生命周期方法构建Widget时调用
    @override
    Widget build(BuildContext context) {
        return Scaffold(
            body: TabBarView(
                physics: NeverScrollableScrollPhysics(),
                controller: _tabController,
                children: <Widget>[
                    //创建之前写好的三个页面，万物皆是Widget
                    PPShopHomePage(title: '首页'),
                    PPMenuPage(title: '菜单'),
                    PPMessageHomePage(title: '消息'),
                    PPMinePage(title: '个人中心')
                ],
            ),
            bottomNavigationBar: Material(
                //底部栏整体的颜色
                color: Colors.blueAccent,
                child: TabBar(
                    controller: _tabController,
                    isScrollable: false,
                    tabs: [
                        Tab(text: "首页", icon: Icon(Icons.home)),
                        Tab(text: "菜单", icon: Icon(Icons.menu)),
                        Tab(text: "消息", icon: Icon(Icons.message)),
                        Tab(text: "我的", icon: Icon(Icons.person))
                    ],
                    //tab被选中时的颜色，设置之后选中的时候，icon和text都会变色
                    labelColor: Colors.amber,
                    //tab未被选中时的颜色，设置之后选中的时候，icon和text都会变色
                    unselectedLabelColor: Colors.black,
                ),
            )
        );
    }

    //组件即将销毁时调用
    @override
    void dispose() {
        super.dispose();
        _tabController.dispose();
    }
}
